Load all required libraries.

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.3     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(broom)

Read in raw data from RDS.

raw_data <- readRDS("./year2.RDS")

Make a few small modifications to names and data for visualizations.

final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
  rename(Facility = wrf) %>%
  mutate(Facility = recode(Facility, 
                           "NO" = "WRF A",
                           "MI" = "WRF B",
                           "CC" = "WRF C"))

Seperate the data by gene target to ease layering in the final plot

#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>% 
  select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
  group_by(date) %>% summarise_if(is.numeric, mean)

#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]

only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]

Build the main plot

      #first layer is the background epidemic curve
        p1 <- only_background %>%
              plotly::plot_ly() %>%
              plotly::add_trace(x = ~date, y = ~new_cases_clarke, 
                                type = "bar", 
                                hoverinfo = "text",
                                text = ~paste('</br> Date: ', date,
                                                     '</br> Daily Cases: ', new_cases_clarke),
                                alpha = 0.5,
                                name = "Daily Reported Cases",
                                color = background_color,
                                colors = background_color,
                                showlegend = FALSE) %>%
            layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #renders the main plot layer two as seven day moving average
        p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke, 
                             type = "scatter",
                             mode = "lines",
                             hoverinfo = "text",
                            text = ~paste('</br> Date: ', date,
                                                     '</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
                             name = "Seven Day Moving Average Athens",
                             line = list(color = seven_day_ave_color),
                             showlegend = FALSE)
      

        
        #renders the main plot layer three as positive target hits
        
        p2 <- plotly::plot_ly() %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n1,
                                       symbol = ~Facility,
                                       marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n2,
                                       symbol = ~Facility,
                                       marker = list(color = '#D95F02', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
            layout(yaxis = list(title = "SARS CoV-2 Copies/L", 
                                 showline = TRUE,
                                 type = "log",
                                 dtick = 1,
                                 automargin = TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #adds the limit of detection dashed line
        p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"), 
                                          xend = ~max(date + 10), 
                                          y = 3571.429, yend = 3571.429,
                                          opacity = 0.35,
                                          line = list(color = "black", dash = "dash")) %>%
          layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y", 
                                    text = "Limit of Detection", showarrow = FALSE))

        

        p1
        p2

Combine the two main plot pieces as a subplot

#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")

#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")


#rejoin the old data frames then seperate in to averages for each plant. 
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)

Build loess smoothing figures figures

This makes the individual plots

#**************************************WRF A PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77', 
              span = 0.3, n = 218)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'

fit_botha
##   [1] 11.53289 11.57123 11.60926 11.64697 11.68439 11.72151 11.75834 11.79485
##   [9] 11.83100 11.86679 11.90226 11.93742 11.97228 12.00688 12.04123 12.07536
##  [17] 12.10926 12.14291 12.17626 12.20929 12.24196 12.27423 12.30632 12.33836
##  [25] 12.37022 12.40176 12.43286 12.46336 12.49315 12.52092 12.54610 12.56959
##  [33] 12.59233 12.61524 12.63924 12.66524 12.69323 12.72223 12.75171 12.78118
##  [41] 12.81012 12.83802 12.86437 12.89091 12.91931 12.94895 12.97920 13.00943
##  [49] 13.03903 13.06736 13.09381 13.11774 13.13853 13.15557 13.16822 13.17877
##  [57] 13.18939 13.19922 13.20742 13.21312 13.21549 13.21368 13.20671 13.19479
##  [65] 13.17878 13.15958 13.13806 13.11511 13.09160 13.06842 13.04130 13.00727
##  [73] 12.96918 12.92987 12.89219 12.85899 12.82661 12.79048 12.75203 12.71267
##  [81] 12.67385 12.63697 12.60349 12.56895 12.52951 12.48749 12.44517 12.40486
##  [89] 12.36888 12.33952 12.31449 12.29024 12.26716 12.24562 12.22601 12.20872
##  [97] 12.19414 12.18422 12.17981 12.17962 12.18236 12.18674 12.19147 12.19527
## [105] 12.19683 12.19487 12.19145 12.18922 12.18781 12.18684 12.18594 12.18471
## [113] 12.18280 12.17929 12.17412 12.16817 12.16232 12.15743 12.15439 12.15407
## [121] 12.15450 12.15364 12.15219 12.15089 12.15045 12.15160 12.15507 12.16125
## [129] 12.16964 12.17960 12.19046 12.20157 12.21230 12.22198 12.23496 12.25425
## [137] 12.27722 12.30122 12.32362 12.34179 12.35307 12.35785 12.35870 12.35630
## [145] 12.35135 12.34452 12.33652 12.32802 12.31970 12.31227 12.30640 12.30278
## [153] 12.30210 12.29945 12.29090 12.27855 12.26449 12.25083 12.23968 12.23313
## [161] 12.23330 12.24229 12.25747 12.27468 12.29367 12.31423 12.33611 12.35908
## [169] 12.38291 12.41320 12.45427 12.50403 12.56037 12.62115 12.68429 12.74766
## [177] 12.80915 12.86665 12.91805 12.96123 12.99409 13.02177 13.05041 13.07941
## [185] 13.10813 13.13598 13.16232 13.18655 13.20803 13.22617 13.24033 13.24991
## [193] 13.25428 13.25283 13.24494 13.23144 13.21383 13.19256 13.16806 13.14076
## [201] 13.11109 13.07950 13.04543 13.00813 12.96772 12.92430 12.87799 12.82891
## [209] 12.77718 12.72281 12.66575 12.60596 12.54343 12.47813 12.41005 12.33914
## [217] 12.26541 12.18881
#assign fits to a vector
both_trenda <- fit_botha

#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax

#reassign dataframes (just to be safe)
work_botha <- wrfa_both

#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date

#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
                    data = smooth_frame_botha,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha,
                                  '</br> Median Log Copies: ', round(both_trenda, digits = 2)),
                    line = list(color = '#1B9E77', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
                                  '</br> Min Log Copies: ', round(both_ymina, digits = 2)),
                    name = "",
                    fillcolor = '#1B9E77',
                    line = list(color = '#1B9E77')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF A") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfa_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#1B9E77', size = 6, opacity = 0.65))

p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02', 
              span = 0.3, n = 218)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'

fit_bothb
##   [1] 10.68637 10.78306 10.87759 10.97003 11.06043 11.14887 11.23539 11.32000
##   [9] 11.40262 11.48321 11.56172 11.63811 11.71234 11.78436 11.85413 11.92167
##  [17] 11.98700 12.05016 12.11114 12.16995 12.22662 12.28115 12.33332 12.38302
##  [25] 12.43040 12.47563 12.51886 12.56025 12.59995 12.63814 12.67479 12.70974
##  [33] 12.74286 12.77399 12.80298 12.82970 12.85153 12.86716 12.87833 12.88679
##  [41] 12.89429 12.90258 12.91341 12.92560 12.93681 12.94706 12.95637 12.96477
##  [49] 12.97228 12.97892 12.98472 12.98969 12.99386 12.99725 12.99988 13.00133
##  [57] 13.00133 13.00010 12.99789 12.99492 12.99144 12.98767 12.98128 12.97067
##  [65] 12.95718 12.94215 12.92693 12.91286 12.90129 12.89356 12.88914 12.88609
##  [73] 12.88365 12.88105 12.87751 12.87227 12.86891 12.87009 12.87368 12.87757
##  [81] 12.87962 12.87769 12.86968 12.85758 12.84472 12.83095 12.81612 12.80008
##  [89] 12.78267 12.76375 12.73938 12.70757 12.67107 12.63263 12.59500 12.56095
##  [97] 12.53321 12.51067 12.48996 12.47048 12.45161 12.43275 12.41327 12.39257
## [105] 12.37003 12.34505 12.32022 12.29773 12.27634 12.25480 12.23189 12.20636
## [113] 12.17697 12.13724 12.08514 12.02616 11.96577 11.90943 11.86262 11.83082
## [121] 11.80000 11.75680 11.70764 11.65896 11.61720 11.58878 11.58015 11.58897
## [129] 11.60703 11.63185 11.66098 11.69198 11.72238 11.74973 11.78800 11.84750
## [137] 11.92030 11.99848 12.07411 12.13927 12.18604 12.22136 12.25723 12.29331
## [145] 12.32927 12.36477 12.39949 12.43307 12.46519 12.49551 12.52369 12.54939
## [153] 12.57229 12.58801 12.59417 12.59343 12.58844 12.58187 12.57636 12.57459
## [161] 12.57920 12.59286 12.61030 12.62524 12.63878 12.65202 12.66608 12.68206
## [169] 12.70105 12.72648 12.75995 12.79984 12.84452 12.89236 12.94175 12.99106
## [177] 13.03866 13.08292 13.12224 13.15497 13.17950 13.19900 13.21764 13.23529
## [185] 13.25181 13.26707 13.28095 13.29329 13.30398 13.31288 13.31986 13.32478
## [193] 13.32751 13.32792 13.32587 13.32158 13.31535 13.30722 13.29720 13.28532
## [201] 13.27160 13.25606 13.23858 13.21905 13.19756 13.17420 13.14907 13.12224
## [209] 13.09381 13.06375 13.03199 12.99851 12.96329 12.92633 12.88760 12.84710
## [217] 12.80482 12.76073
#assign fits to a vector
both_trendb <- fit_bothb

#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax

#reassign dataframes (just to be safe)
work_bothb <- wrfb_both

#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date

#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
                    data = smooth_frame_bothb,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb,
                                  '</br> Median Log Copies: ', round(both_trendb, digits = 2)),
                    line = list(color = '#D95F02', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminb, digits = 2)),
                    name = "",
                    fillcolor = '#D95F02',
                    line = list(color = '#D95F02')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF B") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfb_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#D95F02', size = 6, opacity = 0.65))

p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")

#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************

extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A', 
              span = 0.3, n = 218)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'

fit_bothc
##   [1] 10.75720 10.83391 10.90888 10.98193 11.05286 11.12150 11.18766 11.25156
##   [9] 11.31356 11.37367 11.43188 11.48820 11.54262 11.59515 11.64577 11.69401
##  [17] 11.73958 11.78284 11.82413 11.86379 11.90217 11.93960 11.97387 12.00340
##  [25] 12.02944 12.05329 12.07622 12.09951 12.12444 12.14954 12.17282 12.19475
##  [33] 12.21578 12.23640 12.25704 12.27819 12.29942 12.32008 12.34034 12.36037
##  [41] 12.38032 12.40036 12.42064 12.44113 12.46154 12.48171 12.50147 12.52063
##  [49] 12.53902 12.55647 12.57281 12.58786 12.60144 12.61339 12.62352 12.63463
##  [57] 12.64858 12.66379 12.67866 12.69160 12.70105 12.70540 12.70548 12.70331
##  [65] 12.69913 12.69319 12.68574 12.67702 12.66726 12.65673 12.64064 12.61647
##  [73] 12.58776 12.55809 12.53103 12.51013 12.49338 12.47639 12.45918 12.44176
##  [81] 12.42414 12.40634 12.38837 12.37085 12.35405 12.33749 12.32071 12.30324
##  [89] 12.28459 12.26430 12.24034 12.21226 12.18194 12.15128 12.12218 12.09654
##  [97] 12.07625 12.05832 12.03899 12.01899 11.99906 11.97993 11.96234 11.94702
## [105] 11.93471 11.92614 11.92265 11.92403 11.92867 11.93498 11.94135 11.94619
## [113] 11.94788 11.95171 11.96218 11.97657 11.99215 12.00618 12.01593 12.01866
## [121] 12.01766 12.01754 12.01762 12.01719 12.01557 12.01205 12.00595 11.99136
## [129] 11.96592 11.93420 11.90077 11.87020 11.84706 11.83593 11.83624 11.84272
## [137] 11.85288 11.86425 11.87433 11.88064 11.88069 11.87503 11.86637 11.85543
## [145] 11.84295 11.82967 11.81631 11.80362 11.79233 11.78318 11.77689 11.77421
## [153] 11.77586 11.77910 11.78124 11.78305 11.78533 11.78887 11.79447 11.80292
## [161] 11.81500 11.83152 11.85074 11.87057 11.89128 11.91316 11.93647 11.96149
## [169] 11.98849 12.02239 12.06660 12.11917 12.17813 12.24151 12.30736 12.37371
## [177] 12.43860 12.50006 12.55613 12.60485 12.64425 12.67881 12.71403 12.74945
## [185] 12.78461 12.81907 12.85236 12.88404 12.91365 12.94074 12.96485 12.98554
## [193] 13.00235 13.01482 13.02250 13.02647 13.02806 13.02723 13.02393 13.01810
## [201] 13.00970 12.99867 12.98497 12.96864 12.94975 12.92837 12.90455 12.87838
## [209] 12.84991 12.81913 12.78596 12.75038 12.71239 12.67198 12.62913 12.58384
## [217] 12.53609 12.48588
#assign fits to a vector
both_trendc <- fit_bothc

#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax

#reassign dataframes (just to be safe)
work_bothc <- wrfc_both

#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date

#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
                    data = smooth_frame_bothc,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc,
                                  '</br> Median Log Copies: ', round(both_trendc, digits = 2)),
                    line = list(color = '#E7298A', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminc, digits = 2)),
                    name = "",
                    fillcolor = '#E7298A',
                    line = list(color = '#E7298A')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF C") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfc_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#E7298A', size = 6, opacity = 0.65))

p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")

keeping in case

#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")

#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")

#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")